﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WPF.Element.UI.Communal;

namespace WPF.Element.UI.CustomControls
{
    /// <summary>
    /// 按钮控件
    /// </summary>
    public class ElButton : Button
    {
        static ElButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ElButton), new FrameworkPropertyMetadata(typeof(ElButton)));
        }

        /*  /// <summary>
         /// 注册类型依赖属性   这个类型直接取消吧 直接用backgranda的资源
         /// </summary>
         public static readonly DependencyProperty TypeProperty =
             DependencyProperty.Register(
                 "Size", typeof(ElButtonType), typeof(ElButton), new PropertyMetadata(ElButtonType.Primary, TypeChanged));

        /// <summary>
        /// 属性包装器
        /// </summary>
        public ElButtonType Type
        {
            get { return (ElButtonType)GetValue(TypeProperty); }
            set { SetValue(TypeProperty, value); }
        }

        /// <summary>
        /// 当属性改变时的回调函数（可选）
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        
          private static void TypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            // 当MyProperty值改变时，这里会被调用
            ElButton control = d as ElButton;

            var newValue = (ElButtonType)e.NewValue;

            // 可以在这里添加处理代码
            switch (newValue)
            {
                case ElButtonType.Primary:
                    control.Background = UserResource.GetDynamicResources<SolidColorBrush>("LightPrimaryBrush");
                    break;
                case ElButtonType.Success:
                    control.Background = UserResource.GetDynamicResources<SolidColorBrush>("LightSuccessBrush");
                    break;
                case ElButtonType.Danger:
                    control.Background = UserResource.GetDynamicResources<SolidColorBrush>("LightDangerBrush");
                    break;
                case ElButtonType.Info:
                    control.Background = UserResource.GetDynamicResources<SolidColorBrush>("LightInfoBrush");
                    break;
                case ElButtonType.Text:
                    control.Background = UserResource.GetDynamicResources<SolidColorBrush>("LightTextBrush");
                    break;
                default:
                    Console.WriteLine("这是一个未知数字");
                    break;
            }


        }*/


        /// <summary>
        /// 圆角
        /// </summary>
        public static readonly DependencyProperty ElCornerRadiusProperty =
            DependencyProperty.Register("ElCornerRadius", typeof(CornerRadius), typeof(ElButton));   // new PropertyMetadata(0, null)

        /// <summary>
        /// 圆角 设置这个属性可以直接设置圆角
        /// </summary>
        public CornerRadius ElCornerRadius
        {
            get 
            { 
                return (CornerRadius)GetValue(ElCornerRadiusProperty);
            }
            set 
            {
                SetValue(ElCornerRadiusProperty, value);
            }
        }


        ///// <summary>
        ///// 申明属性 Disabled
        ///// </summary>
        //public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.Register("IsDisabled", typeof(bool), typeof(ElButton));   // new PropertyMetadata(0, null)

        ///// <summary>
        /////是否禁用状态
        ///// </summary>
        //public bool IsDisabled
        //{
        //    get
        //    { 
        //        return (bool)GetValue(IsDisabledProperty);
        //    }
        //    set
        //    { 
        //        SetValue(IsDisabledProperty, value); 
        //    }
        //}

    }
}
